﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
using System.Data;

public partial class EarlyWarning_WarningProcessStop : BasePage
{
    public EarlyWarning_WarningProcessStop()
    { }
    //private static string _AreaID = "320000";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGridView();
        }
    }

    /// <summary>
    /// 绑定药品禁用预警
    /// </summary>
    private void BindGridView()
    {
        int t = 0;
        HZ.Supervise.IBLL.IBLL_PreWarning warning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        HZ.Supervise.Model.DrugPreWarning preWarning = new HZ.Supervise.Model.DrugPreWarning();
        preWarning.IsUsing = false;
        System.Data.DataTable dt = warning.GetDrugPreWarning(preWarning, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                if (row["HospitalID"].ToString() != "所有医院" && row["HospitalName"] == DBNull.Value)
                {
                    row["HospitalName"] = "多家医院";
                }
            }
        }
        AspNetPager1.RecordCount = t;
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    /// <summary>
    /// 开启预警
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_openWarning_Click(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count > 0)
        {
            string id = Request["checkbox1"];
            if (!string.IsNullOrEmpty(id))
            {
                HZ.Supervise.Model.DrugPreWarning drugwar = new DrugPreWarning();
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                string[] arraryIds = id.Split(',');
                foreach (string Item in arraryIds)
                {
                    drugwar.DrugPreWarningID = Item;
                    drugwar.IsUsing = true;
                    int n = pre.UpdateDrugPreWarning(drugwar);

                }
                HZ.Web.WebUtil.Alert("启用成功！");
            }
            else
            {
                HZ.Web.WebUtil.Alert("请选择后在启用！");
            }
        }

        BindGridView();
    }

    /// <summary>
    /// 删除预警
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_delWarning_Click(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count > 0)
        {
            string id = Request["checkbox1"];
            if (!string.IsNullOrEmpty(id))
            {
                HZ.Supervise.Model.DrugPreWarning drugwar = new DrugPreWarning();
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                string[] arraryIds = id.Split(',');
                foreach (string Item in arraryIds)
                {
                    drugwar.DrugPreWarningID = Item;
                    drugwar.IsUsing = false;
                    int n = pre.DeleteDrugPreWarning(drugwar);
                }
            }
            else
            {
                HZ.Web.WebUtil.Alert("请选择后在删除！");
            }
        }

        BindGridView();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabLeve = (Label)e.Row.FindControl("labLeve");

            switch (LabLeve.Text)
            {
                case "1":
                    LabLeve.Text = "一级预警";
                    break;
                case "2":
                    LabLeve.Text = "二级预警";
                    break;
                case "3":
                    LabLeve.Text = "三级预警";
                    break;
            }

            string _HospitalId = ((DataRowView)e.Row.DataItem).Row.ItemArray[9].ToString();
            string _AreaId = ((DataRowView)e.Row.DataItem).Row.ItemArray[1].ToString();

            e.Row.Cells[2].Attributes.Add("onclick", "javascript:window.open('showHospital.aspx?HospitalID=" + Server.UrlEncode(_HospitalId) + "&AreaID=" + Server.UrlEncode(_AreaId) + "','showHospital','width=600,height=400,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0')");
            e.Row.Cells[2].Attributes.Add("onmouseover", "this.style.color='red'");
            e.Row.Cells[2].Attributes.Add("onmouseout", "this.style.color=''");
        }
    }
}
